// pages/index/productList/productList.js
const config = require("../../../utils/config.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    categoryList:[],
    categoryListCopy:[],
    value:"",
    valueCopy:[],
    sear:[]
  },
  upgrade: function () {
    wx.navigateTo({
      url: "../../argent/argent"
    })
  },
  change:function(e){
      this.setData({
        value: e.detail.value
      })
  },
  searchBut:function(e){
    // this.data.categoryList[i].name == this.data.value
    var categoryList = this.data.categoryList;
    this.data.sear=[];
      for (var i = 0; i < this.data.categoryList.length; i++) {
        if (this.data.value != "" && this.data.categoryList[i].name.indexOf(this.data.value)!=-1) {
          console.log(this.data.categoryList[i].name);
          
          this.data.sear.push(this.data.categoryList[i]);
          
        }
      }
    if (this.data.value != "" && this.data.value !=null && this.data.value!=this.data.valueCopy){
        this.setData({
          categoryList: this.data.sear,
          valueCopy:this.data.value
        })
      }
    console.log(this.data.sear)
    // console.log(this.data.categoryList[0].name);
    
    

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      categoryListCopy: JSON.parse(options.categoryList)
    })
    console.log(this.data.categoryListCopy.goodsList)
    if (this.data.categoryListCopy.goodsList!=undefined){
      this.setData({
        categoryList: this.data.categoryListCopy.goodsList
      })
    }else{
      this.setData({
        categoryList: this.data.categoryListCopy
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log(this.data.value)
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})